<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

    <style>
        fieldset{
            width: 500px;
            margin: 150px auto;
            border: 0px;
            padding: 30px;
        }
    </style>
</head>
<body >
<div id="app">

    <fieldset>

        <legend>用户登录</legend>
        <el-form :model="info" status-icon :rules="rules" ref="info" label-width="100px" class="demo-ruleForm">
            <el-form-item label="账号" prop="username">
            <el-input  v-model="info.username"></el-input>
        </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="info.password" ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('info')">提交</el-button>
                <el-button @click="resetForm('info')">重置</el-button>
                <el-button @click="register('info')">用户注册</el-button>
                <el-button @click="updatePassword('info')">忘记密码</el-button>

            </el-form-item>
        </el-form>
    </fieldset>
</div>

<script>
    var haha= new Vue({
        el:"#app",
        data:{

            info:{},
            rules: {
                username: [
                    { required: true, message: '请输入账户', trigger: 'blur' },
                    { min: 3, max: 11, message: '长度在 3 到 11 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 3, max: 11, message: '长度在 3 到 11 个字符', trigger: 'blur' }
                ]

            }
        },
        methods:{
            updatePassword(){
                window.location.href="/demo/userr/updatePassword.html"
            },

            register(){
                window.location.href="/demo/userr/register.html"

            },
            submitForm(formName) {
                haha.$refs[formName].validate((valid) => {
                    if (valid) {
                        $.post("/demo/user/login",haha.info,function (backData) {
                            if(backData.code==0){
                                haha.$notify.error({
                                    title: '温馨提示',
                                    message:backData.msg
                                });
                            }else if (backData.code == 1) {

                                window.location.href = "/demo/userr/main.html";
                            }
                        })
                    }
                });
            },
            resetForm(formName) {
                haha.$refs[formName].resetFields();
            }
        }
    });
</script>
</body>
</html>